#include <iostream>
#include "test.h"
#include "stack.h"

using namespace std;

class squeue
{
public:
    explicit squeue(int sz = 0);
    ~squeue();

    int size();
    bool dequeue(int &value);
    bool inqueue(int value);

private:
    iStack _inq;
    iStack _deq;
};

squeue::squeue(int sz): _inq(sz), _deq(sz)
{
    cout << "squeue constructor" << endl;
}

squeue::~squeue()
{
    cout << "squeue destructor" << endl;
}

int squeue::size()
{
    return (_deq.size() + _inq.size());
}

bool squeue::dequeue(int &value)
{
    if(_deq.empty())
    {
        if(_inq.empty()) return false;

        int tmp;
        while(_inq.size() > 1)
        {
            _inq.pop(tmp);
            _deq.push(tmp);
        }
        cout << "empty sequeue dequeue" << endl;
        return _inq.pop(value);
    }

    return _deq.pop(value);
}

bool squeue::inqueue(int value)
{
    cout << "sequeue inqueue:" << value << endl;
    return _inq.push(value);
}

//test
void stack_queue_test(void)
{
    int tmp = 0, i = 0;
    squeue queue;

    for(i = 0; i < 61; i++)
    {
        if(i%2 == 0)
        {
            queue.inqueue(i);
            cout << "sequeue size:" << queue.size() << endl;
        }

        if(i%10 == 0)
        {
            queue.dequeue(tmp);
            cout << "sequeue dequeue:" << tmp << endl;
        }
    }
}
